%% This script produces Figure 1 in Nucera, Sarno and Zinna "Currency Risk Premiums Redux", published on the RFS
close all

NP1 = 3;
NP2 = 2;

%% panel 1 risk-return trade-off
figure('Name', 'Fig1') 

carry   = repmat([1 1 1], NP, 1);  markertxt = strcat('P', num2str([1:NP]'));
momst   = repmat([2 2 2], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));
momlt   = repmat([3 3 3], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));
value   = repmat([4 4 4], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));
nfa     = repmat([5 5 5], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));
ldc     = repmat([6 6 6], NP1*NP2, 1); markertxt = strvcat(markertxt, strcat('P', num2str([1:NP1*NP2]')));
term    = repmat([7 7 7], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));
yld     = repmat([8 8 8], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));
gap     = repmat([9 9 9], NP, 1);  markertxt = strvcat(markertxt, strcat('P', num2str([1:NP]')));

group   = [carry; momst; momlt; value; nfa; ldc; term; yld; gap;];

Prtfxret = R(:, 1:size(group, 1));
legtxt = strvcat(' ');
wmark = 100;
wlab  = 12;
wtit  = 14;
wax   = 12;
wleg  = 10;

dataploty = nanmean(Prtfxret.*1200,1);  
dataplotx = nanstd(Prtfxret.*100.*sqrt(12),1);
dataplot  = [dataploty' dataplotx'];

subplot(2,1,1)
gscatter(dataplotx,dataploty,group,'kkkkkkk','+o*xsd^v<',10);
xlim([5 11.5])
leg =legend('Carry', 'Mom(ST)', 'Mom(LT)', 'NFA', 'LDC', 'Value', 'Term', 'LYld', 'GAP'); 
legend boxoff  
% c = cellstr(MatPrtLab);
c = cellstr(markertxt);
dx = 0.05; dy = 0.05; % displacement so the text does not overlay the data points
text(dataplotx+dx, dataploty+dy, c,'FontSize',wleg,'fontname','Bookman Old Style');
htit  = title('Panel A: Risk-Return Trade-Off');    
set(htit,'FontSize',wtit,'fontweight','normal','fontname','Bookman Old Style')
xlab=xlabel('$\sigma_{X}(\%)$','Interpreter','Latex');
set(xlab,'FontSize',wlab,'FontWeight','normal','fontname','Bookman Old Style')
ylab=ylabel('$\overline{X}(\%)$','Interpreter','Latex');
set(leg, 'FontSize', wleg, 'fontname','Bookman Old Style')
set(ylab,'FontSize',wlab,'FontWeight','normal','fontname','Bookman Old Style')
set(gca,'FontSize',wax);
set(gca,'fontname','Bookman Old Style');
grid on
box on 

%% panel 2 cumulative HML ret
y1    = hmldata;
y1(isnan(y1))=0;
y1 = cumsum(y1);
x1    = dateP(1:end);
ylim1 = [-Inf Inf];
xlim1 = [dateP(1) dateP(end)];
xlab1 = 'Time';
ylab1 = 'Cum. Returns (%)';
tit1  = 'Panel B: HML Portfolios';
legend1 = strvcat('Carry', 'Mom(ST)', 'Mom(LT)', 'NFA', 'LDC', 'Value', 'Term', 'LYld', 'GAP'); 
% wleg    = 10;
% wtit    = 12;
% wlab    = 10;
ticS1   = 11;
tic1    = dateP((month(dateP) == 1 & mod(year(dateP),5)==0));
wlin1  = [2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2];
clin1 = strvcat('k','r','b','m','g','y', 'r', 'k','r','b','y','k','r','r','b');
clin1 = colormap(gray(size(y1, 2)+2));

tlin1 = strvcat('-','-.','--',':','-','-.','--',':','-','-.','--',':');

subplot(2, 1, 2)

if isempty(clin1)==0
    for jj = 1:size(y1,2)
        plot(x1,y1(:,jj),'Color',clin1(jj,:),'linestyle',tlin1(jj,:),'linewidth',wlin1(jj,:)); hold on
        ylim(ylim1);xlim(xlim1);
    end
else
    plot(x1,y1,'linewidth',wlin1);
    ylim(ylim1);xlim(xlim1);
end

xlab  = xlabel(xlab1);  set(xlab,'FontSize',wlab,'FontWeight','normal','fontname','Bookman Old Style')
ylab  = ylabel(ylab1);  set(ylab,'FontSize',wlab,'FontWeight','normal','fontname','Bookman Old Style')
leg   = legend(legend1);set(leg, 'FontSize',wleg,'fontname','Bookman Old Style'); legend('boxoff')
htit  = title(tit1);    set(htit,'FontSize',wtit,'fontweight','normal','fontname','Bookman Old Style')
set(gca,'XTick',tic1); datetick('x',ticS1,'keepticks','keeplimits');
set(gca,'FontSize',wax);
set(gca,'fontname','Bookman Old Style');
grid on % set(gca,'fontname','Bookman Old Style');